"use strict";
/**
 * @author zhaojiuyi
 * @date 2022/5/30-10:21
 * @version 1.0.0
 */
import api from '@/api/api';
import store from '@/store/index';

export default {
  data() {
    return {
      rules: {
        username: [{
          required: true,
          message: '手机号不能为空',
          trigger: 'blur'
        }, {
          min: 11,
          max: 11,
          message: '请输入11位手机号',
          trigger: 'blur'
        }],
        password: [{
          required: true,
          message: '密码不能为空',
          trigger: 'blur'
        }]
      },
      checked: true,
      loginForm: {
        username: '',
        password: ''
      },
      loading: false
    }
  },
  mounted() {
    //绑定事件，其他界面可能要写在methods里
    window.addEventListener('keydown', this.keyDown);
  },
  methods: {
    keyDown(e) {
      //如果是按回车则执行登录方法
      if (e.keyCode == 13) {
        this.login('loginForm')
      }
    },
    login(loginform) {
      var _this = this;
      let logindata = {
        'phone': this.loginForm.username,
        'password': this.loginForm.password
      };
      api.login().then((response)=>{
        // console.log(response)
      })
      _this.$store.commit('login',true);
      _this.$router.push('/')

      // this.$refs[loginform].validate((valid) => {
      //   if (valid) {
      //     api.login(logindata).then(res => {
      //       if (res.code === 200) {
      //         _this.$router.replace({
      //           path: '/index'
      //         });
      //       } else {
      //         _this.$alert(res.msg, '提示', {
      //           confirmButtonText: '确定'
      //         })
      //       }
      //     })
      //   }
      // });
    }
  },
}
